var t = require("../../../@babel/runtime/helpers/defineProperty"), e = getApp();

Page({
    data: {
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        aideList: []
    },
    onLoad: function(t) {
        this.geTaideList();
    },
    onReady: function() {},
    geTaideList: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.get-list");
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                page: this.data.page
            },
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    var o = a.data.data;
                    if (o && o.length > 0) for (var i = new Date().getTime(), s = 0; s < o.length; s++) {
                        var n = o[s].live_time, r = 1e3 * new Date(n).getTime();
                        o[s].day = "00", o[s].hou = "00", o[s].min = "00", o[s].sec = "00", o[s].bol = !0, 
                        o[s].launch_date = t.formatDate(o[s].live_time), i > r ? o[s].stop = !0 : (t._countDown(s, o[s].live_time), 
                        o[s].stop = !1);
                        var d = o[s].back_open;
                        "[object Boolean]" == Object.prototype.toString.call(d) ? o[s].show = !0 : o[s].show = !1;
                    } else o = [];
                    t.setData({
                        aideList: o,
                        total_page: a.data.last_page
                    });
                } else wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    _timeFormat: function(t) {
        return t < 10 ? "0" + t : t;
    },
    _countDown: function(e, a) {
        var o, i = new Date().getTime(), s = 1e3 * new Date(a).getTime();
        if (s - i > 0) {
            var n, r = (s - i) / 1e3, d = parseInt(r / 86400), c = parseInt(r % 86400 / 3600), u = parseInt(r % 86400 % 3600 / 60), l = parseInt(r % 86400 % 3600 % 60);
            this.setData((t(n = {}, "aideList[" + e + "].day", this._timeFormat(d)), t(n, "aideList[" + e + "].hou", this._timeFormat(c)), 
            t(n, "aideList[" + e + "].min", this._timeFormat(u)), t(n, "aideList[" + e + "].sec", this._timeFormat(l)), 
            n));
        } else {
            var h;
            this.setData((t(h = {}, "aideList[" + e + "].day", "00"), t(h, "aideList[" + e + "].hou", "00"), 
            t(h, "aideList[" + e + "].min", "00"), t(h, "aideList[" + e + "].sec", "00"), t(h, "aideList[" + e + "].stop", !1), 
            h));
        }
        s - i < 0 ? this.setData((t(o = {}, "aideList[" + e + "].day", "00"), t(o, "aideList[" + e + "].hou", "00"), 
        t(o, "aideList[" + e + "].min", "00"), t(o, "aideList[" + e + "].sec", "00"), t(o, "aideList[" + e + "].stop", !1), 
        o)) : this.data.aideList[e].clearTime = setTimeout(this._countDown.bind(this, e, a), 1e3);
    },
    formatDate: function(t) {
        var e = new Date(1e3 * t);
        return e.getFullYear() + "-" + (e.getMonth() + 1) + "-" + e.getDate() + " " + e.getHours() + ":" + e.getMinutes() + ":" + e.getSeconds();
    },
    getMoreData: function() {
        var t = this, a = e.getNetAddresss("plugin.room.frontend.anchor-aide.get-list");
        t.data.isLoadMore = !1, this.data.page >= this.data.total_page || (this.data.page = this.data.page + 1, 
        e._postNetWork({
            url: a,
            showToastIn: !1,
            data: {
                page: this.data.page
            },
            success: function(e) {
                var a = e.data;
                if (1 == a.result) {
                    t.setData({
                        isLoadMore: !0
                    });
                    for (var o = t.data.aideList.concat(a.data.data), i = new Date().getTime(), s = 0; s < o.length; s++) if (!o[s].bol) {
                        var n = o[s].live_time, r = 1e3 * new Date(n).getTime();
                        o[s].day = "00", o[s].hou = "00", o[s].min = "00", o[s].sec = "00", o[s].bol = !0, 
                        o[s].launch_date = t.formatDate(o[s].live_time), i > r ? o[s].stop = !0 : (t._countDown(s, o[s].live_time), 
                        o[s].stop = !1);
                    }
                    t.setData({
                        aideList: o
                    });
                } else t.setData({
                    page: t.data.page - 1,
                    isLoadMore: !1
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        }));
    },
    notapbtn: function() {},
    permissionsBtn: function(t) {
        var e = t.currentTarget.dataset.roomid;
        this.getWatch(e);
    },
    permissionsShowCloseBtn: function() {
        this.setData({
            permissionsShow: !1
        });
    },
    getWatch: function(t) {
        var a = this, o = e.getNetAddresss("plugin.room.frontend.anchor-aide.purview");
        e._postNetWork({
            url: o,
            showToastIn: !1,
            data: {
                id: t
            },
            success: function(t) {
                var e = t.data;
                1 == e.result ? a.setData({
                    WatchList: e.data,
                    permissionsShow: !0
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    onChange: function(t) {
        var e = t.currentTarget.dataset.roomid, a = t.currentTarget.dataset.index;
        this.data.aideList[a].back_open ? this.closeBack(a, e) : this.openBack(a, e);
    },
    openBack: function(a, o) {
        var i = this, s = e.getNetAddresss("plugin.room.frontend.anchor-aide.open-back");
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: {
                id: o
            },
            success: function(e) {
                var o = e.data;
                1 == o.result ? (wx.showToast({
                    icon: "none",
                    title: "成功打开回放",
                    duration: 1500
                }), i.setData(t({}, "aideList[" + a + "].back_open", !0))) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    closeBack: function(a, o) {
        var i = this, s = e.getNetAddresss("plugin.room.frontend.anchor-aide.close-back");
        e._postNetWork({
            url: s,
            showToastIn: !1,
            data: {
                id: o
            },
            success: function(e) {
                var o = e.data;
                1 == o.result ? (wx.showToast({
                    icon: "none",
                    title: "成功关闭回放",
                    duration: 1500
                }), i.setData(t({}, "aideList[" + a + "].back_open", !1))) : wx.showToast({
                    icon: "none",
                    title: o.msg,
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t.msg);
            }
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {
        for (var t = 0; t < this.data.aideList.length; t++) this.data.aideList[t].clearTime && clearTimeout(this.data.aideList[t].clearTime);
    },
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        this.data.isLoadMore ? this.getMoreData() : console.log("没有更多数据");
    },
    onShareAppMessage: function() {},
    goLiveAssistant: function(t) {
        var e = t.currentTarget.dataset.roomid, a = t.currentTarget.dataset.status;
        1 != t.currentTarget.dataset.ban ? 3 == a || 4 == a ? wx.navigateTo({
            url: "/packageD/directSeeding/helperLiveRoom/helperLiveRoom?roomid=" + e
        }) : 1 == a ? wx.showToast({
            icon: "none",
            title: "待审核",
            duration: 1500
        }) : 2 == a && wx.showToast({
            icon: "none",
            title: "等待直播",
            duration: 1500
        }) : wx.showToast({
            icon: "none",
            title: "该直播间已禁用",
            duration: 1500
        });
    }
});